package com.ruoyi.web.controller.ring.app;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.dict.SysNormalDisable;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.HealthQuestion;
import com.ruoyi.ring.domain.dto.UserHealthQuestionDTO;
import com.ruoyi.ring.service.IHealthQuestionAnswerService;
import com.ruoyi.ring.service.IHealthQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 问卷答案 （APP）
 */
@Slf4j
@RestController
@RequestMapping("/ring/app/health_question_answer")
public class AppHealthQuestionAnswerController extends BaseController
{
    @Resource
    private IHealthQuestionAnswerService healthQuestionAnswerService;
    @Resource
    private IHealthQuestionService healthQuestionService;

    /**
     * 获取问卷问题和答案集合 -app
     */
    @GetMapping(value = "/query-questionnaire-questions")
    public AjaxResult queryQuestionnaireQuestions()
    {
        return AjaxResult.success(healthQuestionService.selectHealthQuestionList(Builder.of(HealthQuestion::new).with(HealthQuestion::setStatus, SysNormalDisable.NORMAL.getValue()).build()));
    }
    /**
     * 上报健康问卷-app
     */
    @Log(title = "上报健康问卷", businessType = BusinessType.INSERT)
    @PostMapping("/add-health-question-answer")
    public AjaxResult addHealthQuestionAnswer(@RequestBody UserHealthQuestionDTO userHealthQuestionDTO){
        long userId = SecurityUtils.getUserId();
        log.info("上报健康问卷addHealthQuestionAnswer: userId={}, param={}", userId, JSON.toJSONString(userHealthQuestionDTO));
        return AjaxResult.success(healthQuestionAnswerService.addHealthQuestionAnswer(userHealthQuestionDTO));
    }

    /**
     * 修改健康问卷-app
     */
    @Log(title = "修改健康问卷", businessType = BusinessType.UPDATE)
    @PostMapping("/upd-health-question-answer")
    public AjaxResult updHealthQuestionAnswer(@RequestBody UserHealthQuestionDTO userHealthQuestionDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("修改健康问卷updHealthQuestionAnswer: userId={}, param={}", userId, JSON.toJSONString(userHealthQuestionDTO));
        return toAjax(healthQuestionAnswerService.updHealthQuestionAnswer(userHealthQuestionDTO));
    }
    /**
     * 获取问卷答案详细信息 -app
     */
    @GetMapping(value = "/query-user-health-question")
    public AjaxResult queryUserHealthQuestion()
    {
        return AjaxResult.success(healthQuestionAnswerService.queryUserHealthQuestion());
    }


}
